package com.bzsg.rightsManagementSystem.util.result

object ResultUtil {

    ////对外提供两种获取失败结果result的方式
    ////对外提供一种获取成功的方式


    fun success(data: Any? = null): RequestResult<*> {
        return RequestResult(ResultEnum.SUCCESS.code, ResultEnum.SUCCESS.msg, data)
    }


    /**失败 */
    fun error(errorType: ErrorType): RequestResult<String> {
        return when (errorType) {
            ErrorType.UserExits -> userExist()
            ErrorType.UserNoExits-> userNoExist()
            ErrorType.UserNoLogin -> userNoLogin()
            ErrorType.UserNoPermission -> userNoPermission()
            ErrorType.AccountExpired -> accountExpired()
            ErrorType.PasswordError -> passwordError()
            ErrorType.CredentialsExpired -> credentialsExpired()
            ErrorType.Disabled -> disabled()
            ErrorType.AccountLocked -> accountLocked()
            ErrorType.UNKNOWN -> unknownError()
        }
    }

    //错误
    fun error(resultEnum: ResultEnum): RequestResult<String> {
        return RequestResult(resultEnum.code, resultEnum.msg)
    }
    /**未知错误**/
    private fun unknownError(): RequestResult<String> {
        return RequestResult(ResultEnum.UNKNOWN_ERROR.code, ResultEnum.UNKNOWN_ERROR.msg)
    }

    /**用户存在**/
    private fun userExist(): RequestResult<String> {
        return RequestResult(ResultEnum.USER_IS_EXISTS.code, ResultEnum.USER_IS_EXISTS.msg)
    }

    /**用户不存在**/
    private fun userNoExist(): RequestResult<String> {
        return RequestResult(ResultEnum.USER_NOT_EXIST.code, ResultEnum.USER_NOT_EXIST.msg)
    }

    /**用户没权限**/
    private fun userNoPermission(): RequestResult<String> {
        return RequestResult(ResultEnum.USER_NO_PERMISSION.code, ResultEnum.USER_NO_PERMISSION.msg)
    }

    /**用户未登录**/
    private fun userNoLogin(): RequestResult<String> {
        return RequestResult(ResultEnum.USER_NO_LOGIN.code, ResultEnum.USER_NO_LOGIN.msg)
    }

    /**账号过期**/
    private fun accountExpired(): RequestResult<String> {
        return RequestResult(ResultEnum.ACCOUNT_EXPIRED.code, ResultEnum.ACCOUNT_EXPIRED.msg)
    }

    /**密码过期**/
    private fun passwordError(): RequestResult<String> {
        return RequestResult(ResultEnum.PASSWORD_ERROR.code, ResultEnum.PASSWORD_ERROR.msg)
    }

    /**会话过期**/
    private fun credentialsExpired(): RequestResult<String> {
        return RequestResult(ResultEnum.CREDENTIALS_EXPIRED.code, ResultEnum.CREDENTIALS_EXPIRED.msg)
    }

    /**账号不可用**/
    private fun disabled(): RequestResult<String> {
        return RequestResult(ResultEnum.DISABLED.code, ResultEnum.DISABLED.msg)
    }

    /** 账号锁定 **/
    private fun accountLocked(): RequestResult<String> {
        return RequestResult(ResultEnum.ACCOUNT_LOCKED.code, ResultEnum.ACCOUNT_LOCKED.msg)
    }
}